// import SMERouter from 'sme-router';
import GP21Router from 'gp21-router';

const router = new GP21Router('root');

//导入controllers
import index from '../controllers/index';
import listUser from '../controllers/users/list-user';
import listPositions from '../controllers/position/list-position';
import signin from '../controllers/signin';

import {
  authModel
} from '../models/auth';



// const router = new SMERouter('root');

//拦截守卫
router.use(async (req) => {
  let result = await authModel();
  if (result.ret) {
    router.go(req.url);
  } else {
    router.go('/signin');
  }
});


//配置路由
// router.route('/', signin(router));
router.route('/signin', signin(router));
router.route('/index', index(router));
router.route('/index/users', listUser(router));
router.route('/index/positions', listPositions(router));

router.route('*', (req, res, next) => {
  res.redirect('/index/users')
})


export default router;